package com.example.mall.service.impl;

import com.example.mall.mbg.mapper.RoleMapper;
import com.example.mall.mbg.model.Role;
import com.example.mall.mbg.model.RoleExample;
import com.example.mall.service.RoleService;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * RoleServiceImpl
 * Created by on 2023/12/27.
 */
@Service
public class RoleServiceImpl implements RoleService {
    @Autowired
    private RoleMapper roleMapper;

    @Override
    public List<Role> listAll() {
        return roleMapper.selectByExample(new RoleExample());
    }

    @Override
    public int create(Role role) {
        return roleMapper.insertSelective(role);
    }

    @Override
    public int update(Integer roleid, Role role) {
        role.setRoleid(roleid);
        return roleMapper.updateByPrimaryKeySelective(role);
    }

    @Override
    public int delete(Integer roleid) {
        return roleMapper.deleteByPrimaryKey(roleid);
    }

    @Override
    public List<Role> list(int pageNum, int pageSize) {
        PageHelper.startPage(pageNum, pageSize);
        return roleMapper.selectByExample(new RoleExample());
    }

    @Override
    public Role get(Integer roleid) {
        return roleMapper.selectByPrimaryKey(roleid);
    }
}
